import axios from "axios";
import { Toast } from "vant";
/* import router from "@/router"; */
let loadingToast = null;
axios.defaults.baseURL = "http://localhost:3000";
/* axios.defaults.withCredentials = true; */
/* axios.defaults.headers['X-Request-With'] = 'XMLHttpRequest'; */
/* axios.defaults.headers['token'] = localStorage.getItem('token') || ''; */
/* axios.defaults.headers.post['Content-Type'] = 'application/json'; */
/* axios.interceptors.response.use(res => {
  if (typeof res.data !== 'object') {
    Toast.fail('服务端异常！')
    return Promise.reject(res)
  }
  if (res.data.resultCode != 200) {
    if (res.data.message) Toast.fail(res.data.message)
    if (res.data.resultCode == 416) {
      router.push({ path: '/login' })
    }
    if (res.data.data && window.location.hash == '#/login') {
      setLocal('token', res.data.data)
      axios.defaults.headers['token'] = res.data.data
    }
    return Promise.reject(res.data)
  }

  return res.data
}) */
axios.interceptors.request.use((config)=>{
  loadingToast = Toast.loading({
    duration:0,
    forbidClick:true,
    overlay:true,
    message:"加载中"
  })
  return config
})
axios.interceptors.response.use((res)=>{
  if(res.status != 200){
    Toast.fail("请求异常");
    return Promise.reject(res);
  }
  if(res.status == 200){
    loadingToast.clear();
  }
  return res.data;
})

export default axios